package com.adcc.ags.cgw.service;

import akka.actor.UntypedActor;
import com.adcc.ags.cgw.entity.msg.CGWMsg;
import com.adcc.ags.cgw.entity.msg.TrafficMsg;
import com.adcc.ags.cgw.managed.proxy.MsgProxy;
import com.adcc.utility.log.Log;


/**
 * 基类Actor
 */
public abstract class BaseActorService extends UntypedActor{


    /**
     * 保存报文
     * @param cgwMsg
     */
    protected void saveMsg(CGWMsg cgwMsg){
        try{
            TrafficMsg trafficMsg = new TrafficMsg(cgwMsg);
            MsgProxy.getInstance().getMsgSaveActor().tell(trafficMsg,this.self());
        }catch (Exception ex){
            Log.error(BaseActorService.class.getName(),"saveMsg() error",ex);
        }
    }

    /**
     * 保存报文
     * @param cgwMsg
     * @param sate
     */
    protected void saveMsg(CGWMsg cgwMsg,String sate){
        try{
            TrafficMsg trafficMsg = new TrafficMsg(cgwMsg,sate);
            MsgProxy.getInstance().getMsgSaveActor().tell(trafficMsg,this.self());
        }catch (Exception ex){
            Log.error(BaseActorService.class.getName(),"saveMsg() error",ex);
        }
    }

    /**
     * 保存报文
     * @param cgwMsg
     * @param sate
     * @param errorUser
     * @param errorState
     */
    protected void saveMsg(CGWMsg cgwMsg,String sate,String errorUser,String errorState){
        try{
            TrafficMsg trafficMsg = new TrafficMsg(cgwMsg,sate,errorUser,errorState);
            MsgProxy.getInstance().getMsgSaveActor().tell(trafficMsg,this.self());
        }catch (Exception ex){
            Log.error(BaseActorService.class.getName(),"saveMsg() error",ex);
        }
    }

    @Override
    public void onReceive(Object message) {
        try{
            if(message == null){
                Log.error(BaseActorService.class.getName(), "receive message is null");
                unhandled(message);
            }
        }catch (Exception ex){
            Log.error(BaseActorService.class.getName(), "onReceive() error",ex);
        }
    }
}
